var mysql      = require('mysql');

var connection = mysql.createConnection({
    host     : 'localhost',
    database : "authcenter",
    user     : 'root',
    password : 'root',
    connectTimeout : 10000,
    dateStrings : true
});

connection.connect(function(err) {
    if (err) {
        console.error('error connecting: ' + err.stack);
        return;
    }
    console.log('connected as id ' + connection.threadId);
});
var sql = "select * from user";

connection.query(sql,function(error, rs, fields){
    if (error) throw error;
    console.log("rs = "+ rs.length);
    console.log(rs);
    console.log(rs[0].id + "  " + rs[0].username);
});
connection.end();
console.log(connection.threadId)
/**************************************************************************************************************
 * use mysql with pool
 **************************************************************************************************************/
var pool  = mysql.createPool({
    host     : 'localhost',
    database : "authcenter",
    user     : 'root',
    password : 'root',
    connectTimeout : 10000, // default 10000
    dateStrings : true, // default false
    connectionLimit : 100 // default 10
});

pool.getConnection(function(err, connection) {
    // Use the connection
    connection.query('select * from user', function (error, rs, fields) {
        // And done with the connection.
        connection.release();
        // Handle error after the release.
        if (error) throw error;
        // Don't use the connection here, it has been returned to the pool.
    });
});